<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/view/common/common.jsp" %>


    <script type="text/javascript">
        function searchData() {
            $('#tab').datagrid('load', serializeForm($('#mySearchForm')));
        }

        function edit() {

            var rows = $('#tab').datagrid('getSelections');
            if (rows.length != 1) {
                $.messager.alert('消息', '请选择一条数据!', 'info');
                return false;
            }

            $("#system_user_addDialog").dialog({
                modal: true,
                iconCls: 'icon-edit',
                title: '修改',
                width: 400,
                cache: false,
                shadow: false,
                closed: false
            });


            $('#my_form_update').form('load', {
                id: rows[0].id,
                filePath: rows[0].filePath,
                note: rows[0].note
            });


        }


        function add() {
            $("#system_add_addDialog").form('clear')
            $("#system_add_addDialog").dialog({
                modal: true,
                iconCls: 'icon-add',
                title: '添加',
                width: 400,
                cache: false,
                shadow: false,
                closed: false
            });

        }

        function doSave() {
            var url = path + '/contentFile/insertSelective.do?contentId=${contentId}';
            $("#importForm").form('submit', {
                url: url,
                onSubmit: function () {
                    if ($(this).form('validate') == false) {
                        return false;
                    }
                    if ($("#uploadInfoAdd").val()!=null && $("#uploadInfoAdd").val()!=''){
                        var regXLS = /.*(.jpg|png)$/;
                        if (regXLS.test($("#uploadInfoAdd").val()) == false) {
                            $.messager.alert('消息', '格式不正确!', 'info');
                            return false;
                        }
                    }
                    return true;
                },
                success: function (result) {
                    var result = eval('(' + result + ')');
                    if (result.isSuc) {
                        $.messager.alert('消息', result.msg, 'info');
                        $("#system_add_addDialog").dialog("close");
                        $('#tab').datagrid('reload');
                    } else {
                        $.messager.alert('错误', result.msg, 'error');
                    }
                }
            });
        }

        /**
         * 批量删除
         */
        function batchDelete() {
            var rows = $('#tab').datagrid('getSelections');
            var len = rows.length;
            if (len == 0) {
                $.messager.alert('提示', '请选择数据记录进行操作!', 'info');
                return false;
            } else {
                var ids = '';
                for (var i = 0; i < rows.length; i++) {
                    ids += 'ids=' + rows[i].id + '&';
                }
                ids = ids.substring(0, ids.length - 1);
                var url = path + '/contentFile/delete.do?' + ids;
                $.messager.confirm('提示', '确定要删除选择的数据吗?', function (r) {
                    if (r) {
                        $.get(url, function (result) {
                            if (result.isSuc) {
                                $.messager.alert('提示', result.msg, 'info', function () {
                                    $('#tab').datagrid('reload');
                                });
                            } else {
                                $.messager.alert('提示', result.msg, 'error');
                            }
                        }, 'json');
                    }
                });
            }
        }


        function formatterUrl(value,row,index){
            if(value==null||value==''){
                return '';
            }else{
                return '<a  href="javascript:;" onclick="go(this)" data_url='+row.relativePath+'>查看</a>';
            }

        }

        // function go(obj){
        //     <a href="http://localhost:7080/a/1.jpg" target="_blank"></a>
        // }

        function go(obj){
            var relativePath = $(obj).attr("data_url")
          //  $("#url").attr('src',"${picPath}"+url);
          //   console.info(obj);
          //   console.info(obj.filePath);
          //   console.info(obj.relativePath);
          //   console.info(url);

            $("#url").attr('src',relativePath);

            $("#system_img_addDialog").dialog({
                modal : true,
                title : '图片凭证',
                cache : false,
                shadow:false,
                closed : false,
               // width:800
            });
        }



        function doUpdate() {
            var	url ='${ctx}/contentFile/updateByPrimaryKeySelective.do';
            $("#my_form_update").form('submit', {
                url : url,
                onSubmit : function() {
                    if ($(this).form('validate') == false) {
                        return false;
                    }

                    if ($("#uploadInfoEdit").val()!=null && $("#uploadInfoEdit").val()!=''){
                        var regXLS = /.*(.jpg|png)$/;
                        if (regXLS.test($("#uploadInfoEdit").val()) == false) {
                            $.messager.alert('消息', '格式不正确!', 'info');
                            return false;
                        }
                    }
                    return true;
                },
                success : function(result) {
                    var result = eval('(' + result + ')');
                    if (result.isSuc) {
                        $.messager.alert('消息', result.msg, 'info');
                        $("#system_user_addDialog").dialog("close");
                        $('#tab').datagrid('reload');
                    } else {
                        $.messager.alert('错误', result.msg, 'error');
                    }
                }
            });
        }


    </script>

</head>
<body>

<div class="easyui-panel" fit="true">
    <div id="system_user_list_tb" style="height: auto; padding-left: auto;">

        <a href="#" class="easyui-linkbutton" onclick="add()" data-options="iconCls:'icon-add',plain:true">添加</a>
        <a href="#" class="easyui-linkbutton" onclick="edit()" data-options="iconCls:'icon-edit',plain:true">修改</a>
        <a href="#" class="easyui-linkbutton" onclick="batchDelete()"
           data-options="iconCls:'icon-remove',plain:true">删除</a>
    </div>
    <table id="tab" class="easyui-datagrid" fit="true" style="height:360px;width:auto;"
           url="${ctx}/contentFile/selectList.do?contentId=${contentId}&page=1&rows=1000"
           rownumbers="true" pagination="true" pagePosition="top" singleSelect="true" toolbar="#system_user_list_tb">
        <thead>
        <tr>
            <th field="note" width="180" align="center">凭证说明</th>
            <th field="filePath" width="180" align="center"  data-options="formatter:formatterUrl" >凭证图片</th>

        </tr>
        </thead>
    </table>


    <!-- 修改 ------------start -->
    <div id="system_user_addDialog" class="easyui-dialog" data-options="closed:true" buttons="#addButs1">
        <form id="my_form_update" method="post"  enctype="multipart/form-data" >

            <input type="hidden" id="id" name="id">
            <input type="hidden" id="contentId_edit" name="contentId" value="${contentId}">

            <table style="margin: 10px 20px;">
                <tr>
                    <td style="text-align: right;">凭证说明:</td>
                    <td>
						<textarea id="note_edit" name="note"
                                  style="width: 200px; height: 80px;"
                                  class="easyui-textbox"
                                  data-options="multiline:true,required:true,missingMessage:'为必填项'"></textarea>

                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">凭证图片:</td>
                    <td>
                        <input type="file" id="uploadInfoEdit" name="uploadInfo" style="width: 200px; height: 28px;"
                               class="easyui-validatebox"
                               data-options="required:false,min:0,precision:2,missingMessage:'为必填项'"/>

                    </td>
                </tr>
            </table>
        </form>
        <div id="addButs1">
            <a href="#" class="easyui-linkbutton" onclick="doUpdate()" style="width:80px;height:30px;"
               iconCls="icon-ok">提交</a>
        </div>
    </div>
    <!-- 修改------------end -->
    <!-- 添加 ------------start -->
    <div id="system_add_addDialog" class="easyui-dialog" data-options="closed:true" buttons="#addButs2"
         style="width: 286px;">
        <form id="importForm" method="post" enctype="multipart/form-data">
            <table style="margin: 10px 30px;">
                <tr>
                    <td style="text-align: right;">凭证说明:</td>
                    <td>

                        <%--						<input type="text" id="note_add" name="note"       style="width: 200px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" >--%>

                        <textarea id="note_add" name="note"
                                  style="width: 200px; height: 80px;"
                                  class="easyui-textbox"
                                  data-options="multiline:true,required:true,missingMessage:'为必填项'"></textarea>

                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">凭证图片:</td>
                    <td>
                        <input type="file" id="uploadInfoAdd" name="uploadInfo" style="width: 200px; height: 28px;"
                               class="easyui-validatebox"
                               data-options="required:false,min:0,precision:2,missingMessage:'为必填项'"/>
                    </td>
                </tr>
            </table>
        </form>
        <div id="addButs2">
            <a href="#" class="easyui-linkbutton" onclick="doSave()"
               style="width:80px;height:30px;" iconCls="icon-ok">提交</a>
        </div>
    </div>



    <div id="system_img_addDialog"  class="easyui-dialog"  data-options="closed:true"  buttons="#addButs11">
        <div>
            <a>
                <img src="" style='width : 500px;height : 500px;' id='url'/>
            </a>
        </div>
    </div>

</div>

</body>
</html>
